'''
https://tieba.baidu.com/p/7185877941
爬取视频
'''

import requests
from lxml import etree

url ="https://tieba.baidu.com/p/7185877941"
headers ={
    "User-Agent":'''Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36'''
}
html = requests.get(url=url,headers=headers).text
x = '//div[@class="video_src_wrapper"]/embed/@data-video'
eobj = etree.HTML(html)
video_url_list =eobj.xpath(x) #[<"element at ***">]

if video_url_list:#如果不为空
    video_url = video_url_list[0]
    video_html = requests.get(url=video_url,headers=headers).content#返回字节串
    print(video_html)
    with open('赵丽颖.mp4','wb') as f:
        f.write(video_html)
else:
    print("视频提取失败")


#重要：不要轻信页面中xpath,一切以响应内容为主
